package camid.distribution.lifecycle;

import camid.distribution.activeobject.ObjectRegistry;
import camid.distribution.activeobject.ObjectScheduler;
import camid.distribution.events.FutureNotificator;
import camid.distribution.events.LifecycleEvent;

public abstract class AbstractLifecycleManager 
{
	protected ObjectRegistry registry;
	
	protected FutureNotificator notificator;
	
	public AbstractLifecycleManager( ObjectRegistry registry )
	{
		this.registry = registry;
	}
	
	public AbstractLifecycleManager( ObjectRegistry registry, FutureNotificator notificator)
	{
		this.registry = registry;
		this.notificator = notificator;
	}
	
	public void shutdown()
	{
		registry.shutdown();
	}
	
	public void notifyObjectCreation(String objectId, Class<?> entityClass)
	{
		if( notificator != null )
		{
			notificator.notifyEvent(new LifecycleEvent(objectId, entityClass, LifecycleOperation.CREATION));
		}
	}
	
	public void notifyObjectDestruction(String objectId)
	{
		if( notificator != null )
		{
			notificator.notifyEvent(new LifecycleEvent(objectId, null, LifecycleOperation.DESTRUCTION));
		}
	}
	

	public abstract ObjectScheduler newObject(String objectId, Class<?> entityClass,
			DefaultEntityFactory defaultObjectBuilder)
			throws InstantiationException, IllegalAccessException;

	public abstract ObjectScheduler destroyObject(String objectId);

	public abstract boolean hasObject(String objectId);

	public abstract ObjectScheduler getObject(String objectId);

	public abstract ObjectScheduler insertObject(String objectId, Object entity) throws InstantiationException, IllegalAccessException;

}